<?php

 class DB extends MySQLi
 {

  private $nbQuery;
  private $encodage;

  private $db_host;
  private $db_user;
  private $db_password;
  private $db_dbName;
  private $db_port;
  private $db_socket;

  private $uniqueIdentifier;
  private $connected;


  public function __construct( $db_host     = MYSQL_HOST,
                               $db_port     = MYSQL_PORT,
                               $db_user     = MYSQL_USER,
                               $db_password = MYSQL_PASSWORD,
                               $db_dbName   = MYSQL_DBNAME,
                               $db_socket   = MYSQL_SOCKET )
  {
   $this->nbQuery = 0;

   $this->db_host = $db_host;
   $this->db_user = $db_user;
   $this->db_password = $db_password;
   $this->db_dbName = $db_dbName;
   $this->db_port = $db_port;
   $this->db_socket = $db_socket;

   $this->connected = FALSE;
   $this->uniqueIdentifier = rand();


   switch( MYSQL_ENCODAGE )
   {
    case "_utf8":
     $this->encodage = MYSQL_ENCODAGE;
     break;
    case "_latin1":
     $this->encodage = MYSQL_ENCODAGE;
     break;
    default:
     $this->encodage = "";
   }
  }

  
  public function __destruct()
  {
   //$this->disconnect();
  }


  public function connect()
  {
   parent::init();

   $this->real_connect( $this->db_host,
                        $this->db_user,
                        $this->db_password,
                        $this->db_dbName,
                        $this->db_port,
                        $this->db_socket );
   
   if( $this->connect_errno )
   {
    die('Erreur de connexion : ' . $this->connect_errno . '<br/>' );
    $bReturn = FALSE;
   }
   else
   {
    echo 'Connexion ... OK<br/>';
    $this->connected = TRUE;
    $bReturn = TRUE;
   }

   return $bReturn;
  }


  public function disconnect()
  {
   $bReturn = FALSE;

   if( $this->connected === TRUE && $this->thread_id )
   {
    $this->connected = FALSE;

    if( @$this->close() )
    {
     $bReturn = TRUE;
    }
    else
    {
     ErrorCode::set( 0x00010201 );
     $bReturn = FALSE;
    }
   }
   else
   {
    $bReturn = TRUE;
   }

   return $bReturn;
  }


  public function reconnect()
  {
   $this->disconnect();
   $this->connect();
  }


  public function isConnected()
  {
   if( $this->connected )
   {
    return TRUE;
   }
   else
   {
    return FALSE;
   }
  }


  public function getNextAutoIncrement( $table )
  {
   if( $this->thread_id )
   {
    $query = "SHOW TABLE STATUS FROM `". MYSQL_DBNAME. "` LIKE '". escapeshellcmd( $table ). "';";
    $result = $this->query( $query );

    if( !( $result === FALSE ) )
    {
     $ligne = $result->fetch_object();
     //$result->free;

     return $ligne->Auto_increment;
    }
    else
    {
     ErrorCode::set( 0x00010302 );
     return FALSE;
    }
   }
   else
   {
    ErrorCode::set( 0x00010301 );
    return FALSE;
   }
  }


  public function requete( $query ){ return $this->query( $query ); }
  public function query( $query )
  {
   global $DEBUG_NB_QUERY;

   if( $this->thread_id )
   {
    $this->nbQuery++;
    $DEBUG_NB_QUERY++;
    $result = parent::query( $query );

    if( $result === FALSE )
    {
     ErrorCode::set( 0x0001F000 + sprintf( "0x%02X", $this->errno ), array( "query" => $query, "mysql_errno" => $this->errno, "mysql_error" => $this->error ) );
    }

    return $result;
   }
   else
   {
    return FALSE;
   }
  }


  public function protectDataToDb( $text, $forceQuote=FALSE, $convertCharacterEncoding=TRUE, $strip_tags=TRUE )
  {
   if( $this->thread_id )
   {
    if( $text === NULL )
    {
     $text = "NULL";
    }
    else
    {
     if( get_magic_quotes_gpc() )
     {
      $text = stripslashes( $text );
     }

     // Protection si ce n'est pas un entier
     if( !is_numeric( $text ) || $forceQuote === TRUE )
     {
      if( $convertCharacterEncoding === TRUE )
       $text = $this->convertCharacterEncoding( $text, "UTF-8" );
      $text = $this->encodage. "'". $this->real_escape_string( ( $strip_tags === TRUE ? strip_tags( $text ) : $text ) ). "'";
     }
    }

    return $text;
   }
   else
   {
    ErrorCode::set( 0x00010501 );
    return FALSE;
   }
  }


  public function getNbQuery()
  {
   if( $this->thread_id )
    return $this->nbQuery;
   else
    return 0;
  }


  private function convertCharacterEncoding( $text, $to_encoding="UTF-8", $from_encoding=NULL )
  {
   if( !empty( $text ) )
   {
    switch( $from_encoding )
    {
     case "ASCII": $from_encoding = "ASCII"; break;
     case "UTF-8": $from_encoding = "UTF-8"; break;
     default: $from_encoding = NULL;
    }

    if( $from_encoding == NULL )
     $encodage = mb_detect_encoding( $text, mb_detect_order() );
    else
     $encodage = $from_encoding;

    if( $encodage != "" )
     $text = mb_convert_encoding( $text, $to_encoding, $encodage );
    else if( $to_encoding == "UTF-8" )
     $text = utf8_encode( $text );
   }
   else if( $to_encoding == "UTF-8" )
   {
    $text = utf8_encode( $text );
   }

   return $text;
  }

  public static function htmlaccents( $texte, $invert=FALSE, $utf8=TRUE )
  {
   $array_src = array(
                      "«",
                      "»",
                      "²",
                      "¡",
                      "¿",
                      "š",
                      "Ž",
                      "",
                      "",
                      "ž",
                      "·",
                      "",
                      "©",
                      "®",
                      "€",
                      "",
                      "¢",
                      "£",
                      "¥",
                      "",
                      "á",
                      "Á",
                      "â",
                      "Â",
                      "à",
                      "À",
                      "å",
                      "Å",
                      "ã",
                      "Ã",
                      "ä",
                      "Ä",
                      "æ",
                      "Æ",
                      "ç",
                      "Ç",
                      "é",
                      "É",
                      "ê",
                      "Ê",
                      "è",
                      "È",
                      "ë",
                      "Ë",
                      "í",
                      "Í",
                      "î",
                      "Î",
                      "ì",
                      "Ì",
                      "ï",
                      "Ï",
                      "ñ",
                      "Ñ",
                      "ó",
                      "Ó",
                      "ô",
                      "Ô",
                      "ò",
                      "Ò",
                      "ø",
                      "Ø",
                      "õ",
                      "Õ",
                      "ö",
                      "Ö",
                      "",
                      "",
                      "",
                      "",
                      "ß",
                      "ð",
                      "Ð",
                      "þ",
                      "Þ",
                      "ú",
                      "Ú",
                      "û",
                      "Û",
                      "ù",
                      "Ù",
                      "ü",
                      "Ü",
                      "ý",
                      "Ý",
                      "ÿ",
                      ""
                     );
   $array_dst = array(
                      "&laquo;",
                      "&raquo;",
                      "&sup2;",
                      "&iexcl;",
                      "&iquest;",
                      "&uml;",
                      "&acute;",
                      "&circ;",
                      "&tilde;",
                      "&cedil;",
                      "&middot;",
                      "&bull;",
                      "&copy;",
                      "&reg;",
                      "&curren;",
                      "&euro;",
                      "&cent;",
                      "&pound;",
                      "&yen;",
                      "&fnof;",
                      "&aacute;",
                      "&Aacute;",
                      "&acirc;",
                      "&Acirc;",
                      "&agrave;",
                      "&Agrave;",
                      "&aring;",
                      "&Aring;",
                      "&atilde;",
                      "&Atilde;",
                      "&auml;",
                      "&Auml;",
                      "&aelig;",
                      "&AElig;",
                      "&ccedil;",
                      "&Ccedil;",
                      "&eacute;",
                      "&Eacute;",
                      "&ecirc;",
                      "&Ecirc;",
                      "&egrave;",
                      "&Egrave;",
                      "&euml;",
                      "&Euml;",
                      "&iacute;",
                      "&Iacute;",
                      "&icirc;",
                      "&Icirc;",
                      "&igrave;",
                      "&Igrave;",
                      "&iuml;",
                      "&Iuml;",
                      "&ntilde;",
                      "&Ntilde;",
                      "&oacute;",
                      "&Oacute;",
                      "&ocirc;",
                      "&Ocirc;",
                      "&ograve;",
                      "&Ograve;",
                      "&oslash;",
                      "&Oslash;",
                      "&otilde;",
                      "&Otilde;",
                      "&ouml;",
                      "&Ouml;",
                      "&oelig;",
                      "&OElig;",
                      "&scaron;",
                      "&Scaron;",
                      "&szlig;",
                      "&eth;",
                      "&ETH;",
                      "&thorn;",
                      "&THORN;",
                      "&uacute;",
                      "&Uacute;",
                      "&ucirc;",
                      "&Ucirc;",
                      "&ugrave;",
                      "&Ugrave;",
                      "&uuml;",
                      "&Uuml;",
                      "&yacute;",
                      "&Yacute;",
                      "&yuml;",
                      "&Yuml;"
                     );

   if( $invert === TRUE )
   {
    $texte = str_replace( $array_dst, $array_src, $texte );
   }
   else
   {
    $texte = str_replace( $array_src, $array_dst, $texte );
   }

   if( $utf8 === TRUE )
   {
    $texte = utf8_encode( $texte );
   }

   return $texte;
  }


  public static function removeAccents( $texte )
  {
   $texte = str_replace(
                        array( "á", "Á", "â", "Â", "à", "À", "å", "Å", "ã", "Ã", "ä", "Ä", "æ", "Æ", "ç", "Ç", "é", "É", "ê", "Ê", "è", "È", "ë", "Ë", "í", "Í", "î", "Î", "ì", "Ì", "ï", "Ï", "ñ", "Ñ", "ó", "Ó", "ô", "Ô", "ò", "Ò", "ø", "Ø", "õ", "Õ", "ö", "Ö", "", "", "", "", "ú", "Ú", "û", "Û", "ù", "Ù", "ü", "Ü", "ý", "Ý", "ÿ", "" ),
                        array( "a", "A", "a", "A", "a", "A", "a", "A", "a", "A", "a", "A", "ae", "AE", "c", "C", "e", "E", "e", "E", "e", "E", "e", "E", "i", "I", "i", "I", "i", "I", "i", "I", "n", "N", "o", "O", "o", "O", "o", "O", "o", "O", "o", "O", "o", "O", "oe", "OE", "s", "S", "u", "U", "u", "U", "u", "U", "u", "U", "y", "Y", "y", "Y" ),
                        $texte
                       );
   return $texte;
  }

  public static function textToURI( $texte )
  {
   $texte = trim( $texte );
   $texte = DB::htmlaccents( $texte, TRUE, FALSE );
   $texte = DB::removeAccents( $texte );
   $texte = str_replace( array( "'", " ", "/" ), "-", $texte );
   $texte = str_replace( array( "*", "\\", "&", "^", "~", "$", "€", "£", "š", "%", "§", ",", "?", ";", ":", "!", "<", ">", "#", "{", "\"", "(", "[", "|", "`", ")", "]", "°", "=", "}", ".", "²" ), "", $texte );
   $texte = strtolower( $texte );

   while( strpos( $texte, "--" ) !== FALSE )
    $texte = str_replace( "--", "-", $texte );

   return $texte;
  }

  public static function ucsentences( $sentence_split )
  {
   if( $sentence_split !== NULL )
   {
    $sentence_split = preg_replace( array( '/[!]+/', '/[?]+/', '/[.]+/' ),
                                    array( '!', '?', '.' ),
                                    $sentence_split );

    $textbad = preg_split( "/(\!|\.|\?|\n)/", $sentence_split, -1, PREG_SPLIT_DELIM_CAPTURE );
    $newtext = array();
    $count = sizeof( $textbad );

    foreach( $textbad as $key=>$string )
    {
     if( !empty( $string ) )
     {
      $text = trim( $string, ' ' );
      $size = strlen( $text );

      if( $size > 1 )
      {
       $newtext[] = ucfirst( mb_strtolower( $text ) );
      }
      elseif( $size == 1 )
      {
       $newtext[] = ( $text == "\n" ) ? $text : $text. ' ';
      }
     }
    }

    $newtext = implode( $newtext );
    $newtext = preg_replace( array( '/[!]+/', '/[?]+/' ),
                             array( ' !', ' ?' ),
                             $newtext );
    $newtext = trim( $newtext );
   }
   else
   {
    $newtext = NULL;
   }

   return $newtext;
  }

  public static function slugify($text) {
    $text = DB::removeAccents($text);
    // replace all non letters or digits by -
    $text = preg_replace('/\W+/', '-', $text);

    // trim and lowercase
    $text = strtolower(trim($text, '-'));

    return $text;
  }


 }

?>



<?php

 define( "DEBUG", FALSE );
 $DEBUG_NB_QUERY = 0;

 // MySQL
 define( "MYSQL_HOST", "localhost" ); //mysql5-12.start //localhost
 define( "MYSQL_PORT", "3306" );
 define( "MYSQL_SOCKET", "/var/run/mysqld/mysqld.sock" );
 define( "MYSQL_USER", "root" ); //cpfaizenaybase //root
 define( "MYSQL_PASSWORD", "admin" ); //i1c09a //"admin" // RuptadevVa
 define( "MYSQL_DBNAME_WEBSITE", "cpftmp" );
 define( "MYSQL_DBNAME", MYSQL_DBNAME_WEBSITE );
 define( "MYSQL_ENCODAGE", "_utf8" );
 define( "MYSQL_PHPSESS_TABLE", "php_sessions" );

 ?>

<?php
 echo 'Tentative de connexion ...<br/>';
//connexion to bd
 $myDb = new DB;
 $myDb->connect();

 if( $fp = fopen("../../data/fixtures/fixtures.yml","w") ) {
     echo 'Lecture/Ecriture du fichier fixtures ...<br/>';
 }

 /**********************************************/
 /*                    User                    */
 /**********************************************/


 $query = "SELECT SQL_CALC_FOUND_ROWS `user`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`user` user ";

 echo 'Parsing user...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing user...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
            $userList[] = array(
                "id_user" => $row->id_user,
                "pseudo" => $row->pseudo,
                "datetime_register" => $row->datetime_register,
                "datetime_last_connexion" => $row->datetime_last_connexion,
                "email" => $row->email,
                "password" => $row->password,
                "firstname" => $row->firstname,
                "lastname" => $row->lastname,
                "login_allowed" => $row->login_allowed,
                "id_licensee" => $row->id_licensee,
                "id_file_avatar" => $row->id_file_avatar );
        }
     }

      fputs($fp, "sfGuardUser:\n");
      foreach($userList as $user) {
        fputs($fp, "  sfGuardUser_" . $user["id_user"] . ":\n");
        fputs($fp, "    id: " . $user["id_user"] . "\n");
        fputs($fp, "    username: " . $user["pseudo"] . "\n");
        fputs($fp, "    algorithm: md5\n");
        if($user["pseudo"]  == "Manu"){
            fputs($fp, "    password: i1c09a85\n");
        }else{
            fputs($fp, "    password: " . $user["password"] . "\n");
        }
        fputs($fp, "    email_address: " . $user["email"] . "\n");
        fputs($fp, "    is_active: " . $user["login_allowed"] . "\n");
        if($user["pseudo"]  == "Manu" || $user["pseudo"]  == "Scribe"){
            fputs($fp, "    is_super_admin: true\n");
        }else{
            fputs($fp, "    is_super_admin: false\n");
        }
        fputs($fp, "    created_at: '" . $user["datetime_register"] . "'\n");
        fputs($fp, "    updated_at: '" . $user["datetime_register"] . "'\n");
        fputs($fp, "    last_login: '" . $user["datetime_last_connexion"] . "'\n");
      }

      fputs($fp, "\n");
      fputs($fp, "sfGuardUserProfile:\n");
      foreach($userList as $user) {
        fputs($fp, "  sfGuardUserProfile_" . $user["id_user"] . ":\n");
        fputs($fp, "    id: " . $user["id_user"] . "\n");
        fputs($fp, "    user_id: " . $user["id_user"] . "\n");
        fputs($fp, "    first_name: " . utf8_encode($user["firstname"]) . "\n");
        fputs($fp, "    last_name: " . utf8_encode($user["lastname"]) . "\n");
      }
 }

  /**********************************************/
 /*                 sfAssetFolder              */
 /**********************************************/

fputs($fp, "\n");
  fputs($fp, "sfAssetFolder:
  folder_1:
    id: 1
    name: media
    relative_path: media
    lft: 1
    rgt: 2
    level: 0"
//  folder_2:
//    id: 2
//    name: News
//    relative_path: media/Actualités
//    lft: 2
//    rgt: 3
//    level: 1
//  folder_4:
//    id: 4
//    name: Partenaires
//    relative_path: media/Partenaires
//    lft: 4
//    rgt: 5
//    level: 1"
  );

  fputs($fp, "\n");


 /**********************************************/
 /*                     sfAsset                */
 /**********************************************/

//fputs($fp, "\n");
//  fputs($fp, "sfAsset:
//  asset_1:
//    id: 1
//    folder_id:   2
//    filename:    GnuTuxSoftRevolution-v1.jpg
//    description: GnuTuxSoftRevolution-v1.jpg
//    author:      24
//    type:        image
//    filesize:    223
//  asset_2:
//    id: 2
//    folder_id:   3
//    filename:    thumb-lilian-michon.jpg
//    description: thumb-lilian-michon.jpg
//    author:      24
//    type:        image
//    filesize:    40
//    original_width: 302
//    original_height: 90
//  asset_3:
//    id: 3
//    folder_id:   3
//    filename:    thumb-projet-bois.jpg
//    description: thumb-projet-bois.jpg
//    author:      24
//    type:        image
//    filesize:    12
//    original_width: 321
//    original_height: 80
//  asset_4:
//    id: 4
//    folder_id:   3
//    filename:    thumb-vendee-location.jpg
//    description: thumb-vendee-location.jpg
//    author:      24
//    type:        image
//    filesize:    20
//    original_width: 222
//    original_height: 90
//  asset_5:
//    id: 5
//    folder_id:   3
//    filename:    thumb-dessins-plus.jpg
//    description: thumb-dessins-plus.jpg
//    author:      24
//    type:        image
//    filesize:    14
//    original_width: 127
//    original_height: 90
//  asset_6:
//    id: 6
//    folder_id:   2
//    filename:    00000872-5e4ccd49f57941ada2d87bfc89d3642c.jpg
//    description: 00000872-5e4ccd49f57941ada2d87bfc89d3642c.jpg
//    author:      24
//    type:        image
//    filesize:    235");
//  fputs($fp, "\n");

 /**********************************************/
 /*                 Announcement               */
 /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `announcement`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`announcement` announcement ";

 echo 'Parsing announcement...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing announcement...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
            $announcementList[] = array(
                "id_announcement" => $row->id_announcement,
                "title" => $row->title,
                "description" => $row->description,
                "datetime_creation" => $row->datetime_creation,
                "creation_user" => $row->creation_user,
                "datetime_modification" => $row->datetime_modification,
                "modification_user" => $row->modification_user,
                "type" => $row->type );
        }
     }

      fputs($fp, "\n");
      fputs($fp, "Announcement:\n");
      foreach($announcementList as $announcement) {
        fputs($fp, "  announcement_" . $announcement["id_announcement"] . ":\n");
        fputs($fp, "    id: " . $announcement["id_announcement"] . "\n");
        fputs($fp, "    title: " . utf8_encode($announcement["title"]) . "\n");
        fputs($fp, "    description: " . str_replace(array(":", "\n", "jscripts"), array("&#58;", "", "js"), (DB::htmlaccents($announcement["description"], true, false))) . "\n");
        fputs($fp, "    created_at: '" . $announcement["datetime_creation"] . "'\n");
        fputs($fp, "    creation_user_id: " . $announcement["creation_user"] . "\n");
        fputs($fp, "    updated_at: '" . $announcement["datetime_modification"] . "'\n");
        fputs($fp, "    modification_user_id: " . $announcement["modification_user"] . "\n");
        switch($announcement["type"]) {
          case 'accueil':
              fputs($fp, "    type: home\n");
              break;
          case 'jeunes':
              fputs($fp, "    type: young\n");
              break;
          case 'equipes':
              fputs($fp, "    type: team\n");
              break;
        }
      }
 }

 /**********************************************/
 /*                  Category                  */
 /**********************************************/
 fputs($fp, "\n");
 fputs($fp, "Category:
  menu_1:
    id: 101
    title: Accueil
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /
    publication: published
  menu_2:
    id: 102
    title: Partenaires
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /partenaires-du-club.html
    publication: published
  menu_3:
    id: 103
    title: Forum
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /forums.html
    publication: published
  menu_4:
    id: 104
    title: Galerie photos
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /galerie-photos.html
    publication: published
  menu_5:
    id: 105
    title: Vidéos
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /videos.html
    publication: published
  menu_6:
    id: 106
    title: Le club
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /p/presentation-du-club.html
    publication: published
  menu_7:
    id: 107
    title: Tennis de table
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /calcul-points-matchs-tennis-de-table.html
    publication: published
  sub_menu_9:
    id: 109
    title: Présentation
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /p/presentation-du-club.html
    category_parent_id: 106
    publication: published
  sub_menu_10:
    id: 110
    title: Licenciés
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /licencies.html
    category_parent_id: 106
    publication: published
  sub_menu_11:
    id: 111
    title: Les équipes
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /equipes-du-club.html
    category_parent_id: 106
    publication: published
  sub_menu_12:
    id: 112
    title: Participation du club au frais
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /p/participation-du-club-au-frais.html
    category_parent_id: 106
    publication: published
  sub_menu_13:
    id: 113
    title: Nous contacter
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /contact.html
    category_parent_id: 106
    publication: published
  sub_menu_14:
    id: 114
    title: Calcul points
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /calcul-points-matchs-tennis-de-table.html
    category_parent_id: 107
    publication: published
  sub_menu_15:
    id: 115
    title: Barême des points
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /bareme-des-points.html
    category_parent_id: 107
    publication: published
  sub_menu_16:
    id: 116
    title: Liste des clubs
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /liste-des-clubs-de-tennis-de-table.html
    category_parent_id: 107
    publication: published
  sub_menu_17:
    id: 117
    title: Nous trouver
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /nous-trouver.html
    category_parent_id: 106
    publication: published
    
  footer_18:
    id: 118
    title: Naviguer
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /#
    publication: published
  footer_19:
    id: 119
    title: Informations
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /#
    publication: published
  footer_20:
    id: 120
    title: Credits
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /#
    publication: published
  footer_21:
    id: 121
    title: Qui sommes nous ?
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /#
    publication: published
  sub_footer_22:
    id: 122
    title: Accueil
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /#
    category_parent_id: 118
    publication: published
  sub_footer_23:
    id: 123
    title: Forum
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /forums.html
    category_parent_id: 118
    publication: published
  sub_footer_24:
    id: 124
    title: Galerie photos
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /galerie-photos.html
    category_parent_id: 118
    publication: published
  sub_footer_25:
    id: 125
    title: Vidéos
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /videos.html
    category_parent_id: 118
    publication: published
  sub_footer_26:
    id: 126
    title: Règlement
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /conditions-generales-utilisation.html
    category_parent_id: 119
    publication: published
  sub_footer_27:
    id: 127
    title: Le Club
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /p/presentation-du-club.html
    category_parent_id: 119
    publication: published
  sub_footer_28:
    id: 128
    title: Partenaires
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /partenaires-du-club.html
    category_parent_id: 119
    publication: published
  sub_footer_29:
    id: 129
    title: Contact
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /contact.html
    category_parent_id: 119
    publication: published
  sub_footer_30:
    id: 130
    title: DevBlog
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /p/devblog.html
    category_parent_id: 119
    publication: published
  sub_footer_31:
    id: 131
    title: Développement par Manu
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /profil/couvreur-emmanuel.html
    category_parent_id: 120
    publication: published
  sub_footer_32:
    id: 132
    title: Gestion du contenu par Steph
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /profil/magne-stephane.html
    category_parent_id: 120
    publication: published
  sub_footer_33:
    id: 133
    title: CPFAIZENAY.com est avant toute chose votre site d'actualités pongistes agésinates. CPFAIZENAY se propose de vous faire découvrir l'actualité de notre club, ...
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /p/presentation-du-club.html
    category_parent_id: 121
    publication: published
  sub_footer_34:
    id: 134
    title: Nous trouver
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /nous-trouver.html
    category_parent_id: 119
    publication: published
  sub_footer_35:
    id: 135
    title: Plan du site
    creation_user_id: 24
    modification_user_id: 24
    type: footer
    link: /plan-du-site.html
    category_parent_id: 119
    publication: published
  sub_menu_36:
    id: 136
    title: Coëfficients des compétitions
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /coefficients-des-competitions.html
    category_parent_id: 107
    publication: published
  sub_menu_37:
    id: 137
    title: Liens utiles
    creation_user_id: 24
    modification_user_id: 24
    type: menu
    link: /p/liens.html
    category_parent_id: 107
    publication: published

  videos_33:
    id: 233
    title: Remise des trophées lors de l'AG 2010-2011
    creation_user_id: 24
    modification_user_id: 24
    type: video
    link: /#
    category_parent_id: NULL
    publication: published
  videos_34:
    id: 234
    title: Stage de ping 2010-2011 à Aizenay
    creation_user_id: 24
    modification_user_id: 24
    type: video
    link: /#
    category_parent_id: NULL
    publication: published");

 $query = "SELECT SQL_CALC_FOUND_ROWS `category`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`category` category ";

 echo 'Parsing category...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing category...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
            $categoryList[] = array(
                "id_category" => $row->id_category,
                "title" => $row->title,
                "datetime_creation" => $row->datetime_creation,
                "creation_user" => $row->creation_user,
                "datetime_modification" => $row->datetime_modification,
                "modification_user" => $row->modification_user,
                "order" => $row->order,
                "type" => $row->type );
        }
     }

      fputs($fp, "\n");
      foreach($categoryList as $category) {
        if($category["type"] == "news") {
            fputs($fp, "  news_" . $category["id_category"] . ":\n");
        }else if($category["type"] == "photos") {
            fputs($fp, "  photos_" . $category["id_category"] . ":\n");
        }
        if($category["type"] == "news" || $category["type"] == "photos") {
            fputs($fp, "    id: " . $category["id_category"] . "\n");
            fputs($fp, "    title: " . utf8_encode($category["title"]) . "\n");
            fputs($fp, "    created_at: '" . $category["datetime_creation"] . "'\n");
            fputs($fp, "    creation_user_id: " . $category["creation_user"] . "\n");
            fputs($fp, "    updated_at: '" . $category["datetime_creation"] . "'\n");
            fputs($fp, "    modification_user_id: " . $category["modification_user"] . "\n");
            fputs($fp, "    num_order: " . $category["order"] . "\n");
            switch($category["type"]){
                case "news":
                    fputs($fp, "    type: news\n");
                    break;
                case "photos":
                    fputs($fp, "    type: photo\n");
                    break;
            }
            fputs($fp, "    publication: published\n");
        }
      }
 }

 /**********************************************/
 /*                    News                    */
 /**********************************************/

     
 $query = "SELECT SQL_CALC_FOUND_ROWS `news`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`news` news ";
 
 echo 'Parsing news...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing news...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $newsList[] = array(

                    "id_news" => $row->id_news,
                    "title" => $row->title,
                    "publication" => $row->publication,
                    "text" => $row->text,
                    "category" => $row->category,
                    "id_category" => $row->id_category,
                    "datetime_creation" => $row->datetime_creation,
                    "creation_user" => $row->creation_user,
                    "datetime_modification" => $row->datetime_modification,
                    "modification_user" => $row->modification_user);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "News:\n");
      foreach($newsList as $news) {
        fputs($fp, "  news_" . $news["id_news"] . ":\n");
        fputs($fp, "    id: " . $news["id_news"] . "\n");
        fputs($fp, "    title: " . utf8_encode($news["title"]) . "\n");
        fputs($fp, "    text: " . str_replace(array(":", "\n", "jscripts"), array("&#58;", "", "js"), (DB::htmlaccents($news["text"], true, false))) . "\n");
        fputs($fp, "    created_at: '" . $news["datetime_creation"] . "'\n");
        fputs($fp, "    creation_user_id: " . $news["creation_user"] . "\n");
        fputs($fp, "    updated_at: '" . $news["datetime_modification"] . "'\n");
        fputs($fp, "    modification_user_id: " . $news["modification_user"] . "\n");
        fputs($fp, "    publication: published\n");
        fputs($fp, "    category_id: " . $news["id_category"] . "\n");
//        fputs($fp, "    asset_id: 6\n");
        $kind = 'adult';
        switch($news["category"]){
            case 'adultes': $kind = 'adult'; break;
            case 'jeunes': $kind = 'young'; break;
        }
        fputs($fp, "    kind: " . $kind . "\n");
      }
      
  }

 /**********************************************/
 /*                    Events                  */
 /**********************************************/

  $query = "SELECT SQL_CALC_FOUND_ROWS `events`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`events` events ";

 echo 'Parsing events...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing events...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $eventsList[] = array(

                    "id_event" => $row->id_event,
                    "id_news" => $row->id_news,
                    "date_event" => $row->date_event);
           }
      }
      
      fputs($fp, "\n");
      fputs($fp, "Event:\n");
      foreach($eventsList as $event) {
        foreach($newsList as $news) {
            if($event["id_news"] == $news["id_news"]){
                fputs($fp, "  event_" . $event["id_event"] . ":\n");
                fputs($fp, "    id: " . $event["id_event"] . "\n");
                fputs($fp, "    datetime_event: '" . $event["date_event"] . "'\n");
                fputs($fp, "    title: " . utf8_encode($news["title"]) . "\n");
                fputs($fp, "    text: " . str_replace(array(":", "\n", "jscripts"), array("&#58;", "", "js"), (DB::htmlaccents($news["text"], true, false))) . "\n");
                fputs($fp, "    created_at: '" . $news["datetime_creation"] . "'\n");
                fputs($fp, "    creation_user_id: " . $news["creation_user"] . "'\n");
                fputs($fp, "    updated_at: '" . $news["datetime_modification"] . "'\n");
                fputs($fp, "    modification_user_id: " . $news["modification_user"] . "\n");
                fputs($fp, "    publication: published\n");
//                fputs($fp, "    asset_id: 1\n");
            }
        }
      }
 }

 /**********************************************/
 /*                    Teams                   */
 /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `teams`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`teams` teams ";

 echo 'Parsing teams...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing teams...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $teamsList[] = array(

                    "id_team" => $row->id_team,
                    "name" => $row->name,
                    "category" => $row->category,
                    "presentation" => $row->presentation,
                    "datetime_creation" => $row->datetime_creation,
                    "creation_user" => $row->creation_user,
                    "datetime_modification" => $row->datetime_modification,
                    "modification_user" => $row->modification_user,
                    "order" => $row->order);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "Team:\n");
      foreach($teamsList as $team) {
        fputs($fp, "  team_" . $team["id_team"] . ":\n");
        fputs($fp, "    id: " . $team["id_team"] . "\n");
        fputs($fp, "    name: " . utf8_encode($team["name"]) . "\n");
        fputs($fp, "    content: " . str_replace(array(":", "\n", "jscripts"), array("&#58;", "", "js"), (DB::htmlaccents($team["presentation"], true, false))) . "\n");
        fputs($fp, "    team_category: " . utf8_encode($team["category"]) . "\n");
        fputs($fp, "    created_at: '" . $team["datetime_creation"] . "'\n");
        fputs($fp, "    creation_user_id: " . $team["creation_user"] . "\n");
        fputs($fp, "    updated_at: '" . $team["datetime_modification"] . "'\n");
        fputs($fp, "    modification_user_id: " . $team["modification_user"] . "\n");
        fputs($fp, "    num_order: " . $team["order"] . "\n");
//        fputs($fp, "    asset_id: 1\n");
      }


  }

 /**********************************************/
 /*                    Club                    */
 /**********************************************/

  fputs($fp, "\n");
  fputs($fp, "Club:
  club_1:
    id: 1
    name: CPF Aizenay
    city_id: NULL
    club_number: '04850028'
    website: http://www.cpfaizenay.com");
  fputs($fp, "\n");

 /**********************************************/
 /*                  Licensee                  */
 /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `licensee`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`licensee` licensee ";

 echo 'Parsing licensee...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing licensee...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $licenseeList[] = array(

                    "id_licensee" => $row->id_licensee,
                    "licensee_number" => $row->licensee_number,
                    "lastname" => $row->lastname,
                    "firstname" => $row->firstname,
                    "category" => $row->category,
                    "detailled_category" => $row->detailled_category,
                    "club" => $row->club,
                    "status" => $row->status,
                    "id_team" => $row->id_team);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "Licensee:\n");
      foreach($licenseeList as $licensee) {
        fputs($fp, "  licensee_" . $licensee["id_licensee"] . ":\n");
        fputs($fp, "    id: " . $licensee["id_licensee"] . "\n");
        fputs($fp, "    licensee_number: " . $licensee["licensee_number"] . "\n");
        fputs($fp, "    lastname: " . utf8_encode($licensee["lastname"]) . "\n");
        fputs($fp, "    firstname: " . utf8_encode($licensee["firstname"]) . "\n");
        fputs($fp, "    category: " . $licensee["category"]. ($licensee["category"] != 'S' ? $licensee["detailled_category"] : '') . "\n");
        fputs($fp, "    status: " . $licensee["status"] . "\n");
        fputs($fp, "    club_id: 1\n");
        fputs($fp, "    team_id: " . $licensee["id_team"] . "\n");

        $query = "SELECT SQL_CALC_FOUND_ROWS `user`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`user` user ";

         echo 'Parsing user...<br/>';
         if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
             echo 'Parsing user...OK<br/>';

             if( $result->num_rows > 0 ) {
                while( $row = $result->fetch_object() ){
                    if($row->id_licensee == $licensee["id_licensee"]){
                        fputs($fp, "    licensee_user_id: " . $row->id_user . "\n");
                    }
                }
            }
         }
      }
  }

 /**********************************************/
 /*                 Licensee Points            */
 /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `licensee_points`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`licensee_points` licensee_points ";

 echo 'Parsing licensee_points...<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing licensee_points...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $licenseePointsList[] = array(

                    "id_licensee_points" => $row->id_licensee_points,
                    "id_licensee" => $row->id_licensee,
                    "datetime_points_modification" => $row->datetime_points_modification,
                    "datetime_points_creation" => $row->datetime_points_creation,
                    "nb_points" => $row->nb_points,
                    "creation_user" => $row->creation_user,
                    "modification_user" => $row->modification_user);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "LicenseePoint:\n");
      foreach($licenseePointsList as $licenseePoint) {
          if(!empty($licenseePoint["nb_points"])){
            fputs($fp, "  licenseePoint_" . $licenseePoint["id_licensee_points"] . ":\n");
            fputs($fp, "    id: " . $licenseePoint["id_licensee_points"] . "\n");
            fputs($fp, "    licensee_id: " . $licenseePoint["id_licensee"] . "\n");
            fputs($fp, "    nb_points: " . $licenseePoint["nb_points"] . "\n");
            fputs($fp, "    nb_points_fftt: " . $licenseePoint["nb_points"] . "\n");
            fputs($fp, "    creation_user_id: " . $licenseePoint["creation_user"] . "\n");
            fputs($fp, "    modification_user_id: " . $licenseePoint["modification_user"] . "\n");
            fputs($fp, "    datetime_points: '" . $licenseePoint["datetime_points_creation"] . "'\n");
          }
      }
  }

 /**********************************************/
 /*                    Drift                   */
 /**********************************************/

  fputs($fp, "\n");
  fputs($fp, "Drift:
  drift_1:
    id: 1
    value: 2.10
    datetime_drift: '2010-12-01'");
  fputs($fp, "\n");

 /**********************************************/
 /*                     Pages                  */
 /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `pages`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`pages` pages ";

 echo 'Parsing pages..<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing pages...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $pagesList[] = array(

                    "id_page" => $row->id_page,
                    "id_category" => $row->id_category,
                    "title" => $row->title,
                    "content" => $row->content,
                    "creation_user" => $row->creation_user,
                    "modification_user" => $row->modification_user,
                    "datetime_creation" => $row->datetime_creation,
                    "datetime_modification" => $row->datetime_modification);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "Page:\n");
      foreach($pagesList as $page) {
        fputs($fp, "  page_" . $page["id_page"] . ":\n");
        fputs($fp, "    id: " . $page["id_page"] . "\n");
        fputs($fp, "    title: " . utf8_encode($page["title"]) . "\n");
        fputs($fp, "    content: " . str_replace(array(":", "\n", "jscripts"), array("&#58;", "", "js"), (DB::htmlaccents($page["content"], true, false))) . "\n");
        fputs($fp, "    creation_user_id: " . $page["creation_user"] . "\n");
        fputs($fp, "    modification_user_id: " . $page["modification_user"] . "\n");
        fputs($fp, "    created_at: '" . $page["datetime_creation"] . "'\n");
        fputs($fp, "    updated_at: '" . $page["datetime_modification"] . "'\n");
      }
  }
  
 /**********************************************/
 /*                    MatchType               */
 /**********************************************/

  fputs($fp, "\n");
  fputs($fp, "MatchType:
  matchType_1:
    id: 1
    title: Championnats de France (y compris barrages et titres) (N, R, D)
    coefficient: 1
    type: team
  matchType_2:
    id: 2
    title: Challenge Bernard Jeu (N, R)
    coefficient: 0.75
    type: team
  matchType_3:
    id: 3
    title: Championnat de France des Régions (N)
    coefficient: 0.75
    type: team
  matchType_4:
    id: 4
    title: Coupe nationale vétérans (N,R,D)
    coefficient: 0.75
    type: team
  matchType_5:
    id: 5
    title: Coupe nationale corporative
    coefficient: 1
    type: team
  matchType_6:
    id: 6
    title: Interclubs jeunes (N, R, D)
    coefficient: 0.5
    type: team
  matchType_7:
    id: 7
    title: Autres compétitions par équipes régionales et départementales
    coefficient: 0.5
    type: team
  matchType_8:
    id: 8
    title: Championnats de France senior (N)
    coefficient: 1.5
    type: individual
  matchType_9:
    id: 9
    title: TOP National
    coefficient: 1.5
    type: individual
  matchType_10:
    id: 10
    title: Critérium Fédéral Senior (N, R, D)
    coefficient: 1.25
  matchType_11:
    id: 11
    title: Finales par classement (N, R, D)
    coefficient: 1.25
    type: individual
  matchType_12:
    id: 12
    title: Championnats de France Jeunes (N, R, D)
    coefficient: 1
    type: individual
  matchType_13:
    id: 13
    title: Critérium Fédéral Jeunes (N, R, D)
    coefficient: 1
    type: individual
  matchType_14:
    id: 14
    title: Finales Individuelles (R, D)
    coefficient: 1
    type: individual
  matchType_15:
    id: 15
    title: Championnats de France Vétérans (N, R, D)
    coefficient: 1
    type: individual
  matchType_16:
    id: 16
    title: Championnats de France Corporatifs (N, R, D)
    coefficient: 1
    type: individual
  matchType_17:
    id: 17
    title: Tournois Nationaux et Internationaux joués en France
    coefficient: 0.75
    type: individual
  matchType_18:
    id: 18
    title: Autre compétitions individuelles régionales et départementales
    coefficient: 0.5
    type: individual
  matchType_19:
    id: 19
    title: Une épreuve individuelle ou par équipes au choix par ligue (R)
    coefficient: 0.75
    type: NULL
  matchType_20:
    id: 20
    title: Une épreuve individuelle ou par équipes au choix par département (D)
    coefficient: 0.75
    type: NULL");
  fputs($fp, "\n");

 /**********************************************/
 /*                 LicenseeMatch              */
 /**********************************************/

  fputs($fp, "\n");
  fputs($fp, "LicenseeMatch:
  licensee_match_1:
    id: 1
    licensee_id: 91
    datetime_match: '2011-09-25 00:00:00'
    status: 'V'
    opponent_lastname: SALOMOND
    opponent_firstname: Arnaud
    opponent_point: 1176
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_2:
    id: 2
    licensee_id: 91
    datetime_match: '2011-09-25 00:00:00'
    status: 'V'
    opponent_lastname: CROCHET
    opponent_firstname: Philippe
    opponent_point: 1214
    opponent_licensee_number: 68845
    match_type_id: 1
  licensee_match_3:
    id: 3
    licensee_id: 91
    datetime_match: '2011-09-25 00:00:00'
    status: 'V'
    opponent_lastname: AVOINE
    opponent_firstname: Médhy
    opponent_point: 569
    opponent_licensee_number: 8523611
    match_type_id: 1
  licensee_match_4:
    id: 4
    licensee_id: 91
    datetime_match: '2011-10-09 00:00:00'
    status: 'D'
    opponent_lastname: RENARD
    opponent_firstname: Rémi
    opponent_point: 1260
    opponent_licensee_number: 868443
    match_type_id: 1
  licensee_match_5:
    id: 5
    licensee_id: 91
    datetime_match: '2011-10-09 00:00:00'
    status: 'V'
    opponent_lastname: CHAILLOLEAU
    opponent_firstname: Maxime
    opponent_point: 1446
    opponent_licensee_number: 8513468
    match_type_id: 1
  licensee_match_6:
    id: 6
    licensee_id: 91
    datetime_match: '2011-10-09 00:00:00'
    status: 'V'
    opponent_lastname: PONT
    opponent_firstname: Yoann
    opponent_point: 1432
    opponent_licensee_number: 859468
    match_type_id: 1
  licensee_match_7:
    id: 7
    licensee_id: 91
    datetime_match: '2011-10-15 00:00:00'
    status: 'D'
    opponent_lastname: SOULARD
    opponent_firstname: Adrien
    opponent_point: 1710
    opponent_licensee_number: 8514627
    match_type_id: 10
  licensee_match_8:
    id: 8
    licensee_id: 91
    datetime_match: '2011-10-15 00:00:00'
    status: 'V'
    opponent_lastname: SOTA
    opponent_firstname: Philippe
    opponent_point: 1615
    opponent_licensee_number: 781315
    match_type_id: 10
  licensee_match_9:
    id: 9
    licensee_id: 91
    datetime_match: '2011-10-15 00:00:00'
    status: 'V'
    opponent_lastname: LECOMTE
    opponent_firstname: Bertrand
    opponent_point: 1560
    opponent_licensee_number: 868443
    match_type_id: 10
  licensee_match_10:
    id: 10
    licensee_id: 91
    datetime_match: '2011-10-15 00:00:00'
    status: 'V'
    opponent_lastname: GUILLOIS
    opponent_firstname: Kévin
    opponent_point: 1395
    opponent_licensee_number: 868443
    match_type_id: 10
  licensee_match_11:
    id: 11
    licensee_id: 91
    datetime_match: '2011-10-15 00:00:00'
    status: 'V'
    opponent_lastname: TREGUER
    opponent_firstname: Cédric
    opponent_point: 1360
    opponent_licensee_number: NULL
    match_type_id: 10
  licensee_match_12:
    id: 12
    licensee_id: 91
    datetime_match: '2011-10-23 00:00:00'
    status: 'V'
    opponent_lastname: MORIN
    opponent_firstname: Romuald
    opponent_point: 1229
    opponent_licensee_number: 8521133
    match_type_id: 1
  licensee_match_13:
    id: 13
    licensee_id: 91
    datetime_match: '2011-10-23 00:00:00'
    status: 'V'
    opponent_lastname: FROMONT
    opponent_firstname: Alexis
    opponent_point: 950
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_14:
    id: 14
    licensee_id: 91
    datetime_match: '2011-10-23 00:00:00'
    status: 'V'
    opponent_lastname: GUINOT
    opponent_firstname: Damien
    opponent_point: 900
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_15:
    id: 15
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'D'
    opponent_lastname: GUENNOUNI
    opponent_firstname: Medhi
    opponent_point: 1570
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_16:
    id: 16
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: GARCIN
    opponent_firstname: Benjamin
    opponent_point: 1420
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_17:
    id: 17
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: PILON
    opponent_firstname: Jérémie
    opponent_point: 1380
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_18:
    id: 18
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: RENAUD
    opponent_firstname: Djimmy
    opponent_point: 1630
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_19:
    id: 19
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: PINEAU
    opponent_firstname: Ludovic
    opponent_point: 1220
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_20:
    id: 20
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'D'
    opponent_lastname: ROBIN
    opponent_firstname: Dimitri
    opponent_point: 1450
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_21:
    id: 21
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: CORNUAILLE
    opponent_firstname: Antoine
    opponent_point: 1220
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_22:
    id: 22
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: PINEAU
    opponent_firstname: Ludovic
    opponent_point: 1220
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_23:
    id: 23
    licensee_id: 91
    datetime_match: '2011-10-29 00:00:00'
    status: 'V'
    opponent_lastname: FRANCOIS
    opponent_firstname: Sébastien
    opponent_point: 980
    opponent_licensee_number: NULL
    match_type_id: 18
  licensee_match_24:
    id: 24
    licensee_id: 91
    datetime_match: '2011-11-06 00:00:00'
    status: 'V'
    opponent_lastname: BROCHARD
    opponent_firstname: Kévin
    opponent_point: 713
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_25:
    id: 25
    licensee_id: 91
    datetime_match: '2011-11-06 00:00:00'
    status: 'V'
    opponent_lastname: GARO
    opponent_firstname: Maëlik
    opponent_point: 850
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_26:
    id: 26
    licensee_id: 91
    datetime_match: '2011-11-06 00:00:00'
    status: 'V'
    opponent_lastname: BRETHOME
    opponent_firstname: Clément
    opponent_point: 950
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_27:
    id: 27
    licensee_id: 91
    datetime_match: '2011-11-20 00:00:00'
    status: 'D'
    opponent_lastname: JOBARD
    opponent_firstname: Hervé
    opponent_point: 1120
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_28:
    id: 28
    licensee_id: 91
    datetime_match: '2011-11-20 00:00:00'
    status: 'V'
    opponent_lastname: LEROGNON
    opponent_firstname: Johan
    opponent_point: 1250
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_29:
    id: 29
    licensee_id: 91
    datetime_match: '2011-11-20 00:00:00'
    status: 'V'
    opponent_lastname: MICHAUD
    opponent_firstname: Malika
    opponent_point: 1120
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_30:
    id: 30
    licensee_id: 91
    datetime_match: '2011-11-27 00:00:00'
    status: 'V'
    opponent_lastname: BILLET
    opponent_firstname: Sophie
    opponent_point: 1140
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_31:
    id: 31
    licensee_id: 91
    datetime_match: '2011-11-27 00:00:00'
    status: 'D'
    opponent_lastname: ARNAUD
    opponent_firstname: Florian
    opponent_point: 1300
    opponent_licensee_number: NULL
    match_type_id: 1
  licensee_match_32:
    id: 32
    licensee_id: 91
    datetime_match: '2011-11-27 00:00:00'
    status: 'V'
    opponent_lastname: GUITTON
    opponent_firstname: Jimmy
    opponent_point: 1480
    opponent_licensee_number: NULL
    match_type_id: 1");
  
  fputs($fp, "\n");

 /**********************************************/
 /*                 Partner                    */
 /**********************************************/

  fputs($fp, "\n");
  fputs($fp, "Partner:
 partner_1:
    id: 1
    title: Lilian Michon
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_2:
    id: 2
    title: Projet Bois
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_3:
    id: 3
    title: Vendée Location
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_4:
    id: 4
    title: Dessins +
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_5:
    id: 5
    title: Alain Legrand
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_6:
    id: 6
    title: ATP Immobilier
    link: http://www.fnaim.fr/atpimmobilier
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_7:
    id: 7
    title: Auto Ecole Passeport
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_8:
    id: 8
    title: Christi Fleurs
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_9:
    id: 9
    title: Credit Mutuel
    link: http://www.creditmutuel.fr
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_10:
    id: 10
    title: Hair du temps
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_11:
    id: 11
    title: Maison bleue
    link: http://www.maisonbleue.fr
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_12:
    id: 12
    title: Parfums vendanges
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_13:
    id: 13
    title: Charcuterie Roirand
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_14:
    id: 14
    title: Hyper U
    link: http://www.hyperu-aizenay.com
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_15:
    id: 15
    title: Parfums vendanges
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null
 partner_16:
    id: 16
    title: Intersport
    creation_user_id: 24
    modification_user_id: 24
    asset_id: null");

  fputs($fp, "\n");

 /**********************************************/
 /*                 ScoringTable               */
 /**********************************************/

  fputs($fp, "\n");
  fputs($fp, "ScoringTable:
 scoringTable_1:
    points_away: 0
    normal_victory: 6
    normal_defeat: -5
    anormal_victory: 6
    anormal_defeat: -5
 scoringTable_2:
    points_away: 25
    normal_victory: 5.5
    normal_defeat: -4.5
    anormal_victory: 7
    anormal_defeat: -6
 scoringTable_3:
    points_away: 50
    normal_victory: 5
    normal_defeat: -4
    anormal_victory: 8
    anormal_defeat: -7
 scoringTable_4:
    points_away: 100
    normal_victory: 4
    normal_defeat: -3
    anormal_victory: 10
    anormal_defeat: -8
 scoringTable_5:
    points_away: 150
    normal_victory: 3
    normal_defeat: -2
    anormal_victory: 13
    anormal_defeat: -10
 scoringTable_6:
    points_away: 200
    normal_victory: 2
    normal_defeat: -1
    anormal_victory: 17
    anormal_defeat: -12.5
 scoringTable_7:
    points_away: 300
    normal_victory: 1
    normal_defeat: -0.5
    anormal_victory: 22
    anormal_defeat: -16
 scoringTable_8:
    points_away: 400
    normal_victory: 0.5
    normal_defeat: 0
    anormal_victory: 28
    anormal_defeat: -20
 scoringTable_9:
    points_away: 500
    normal_victory: 0
    normal_defeat: 0
    anormal_victory: 40
    anormal_defeat: -29");
  
  fputs($fp, "\n");


  /**********************************************/
  /*                 sfAssetMedia               */
  /**********************************************/

//  fputs($fp, "\n");
//  fputs($fp, "sfAssetMedia:
// sfAssetMedia_1:
//    category_id: 19
//    asset_id: 1
//    creation_user_id: 24
//    modification_user_id: 24
//    created_at: 2011-14-10
//    updated_at: 2011-14-10
// sfAssetMedia_2:
//    category_id: 19
//    asset_id: 2
//    creation_user_id: 24
//    modification_user_id: 24
//    created_at: 2011-14-10
//    updated_at: 2011-14-10
// sfAssetMedia_3:
//    category_id: 26
//    asset_id: 3
//    creation_user_id: 24
//    modification_user_id: 24
//    created_at: 2011-14-10
//    updated_at: 2011-14-10
// sfAssetMedia_4:
//    category_id: 27
//    asset_id: 1
//    creation_user_id: 24
//    modification_user_id: 24
//    created_at: 2011-14-10
//    updated_at: 2011-14-10
// sfAssetMedia_5:
//    category_id: 27
//    asset_id: 4
//    creation_user_id: 24
//    modification_user_id: 24
//    created_at: 2011-14-10
//    updated_at: 2011-14-10");


  /**********************************************/
  /*                   Comments                 */
  /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `news_comments`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`news_comments` news_comments ";

 echo 'Parsing news_comments..<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing news_comments...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $newsCommentsList[] = array(

                    "id_news_comments" => $row->id_news_comments,
                    "id_news" => $row->id_news,
                    "creation_user" => $row->creation_user,
                    "datetime_creation" => $row->datetime_creation,
                    "modification_user" => $row->modification_user,
                    "datetime_modification" => $row->datetime_creation,
                    "text" => $row->text);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "Comment:\n");
      foreach($newsCommentsList as $newsComment) {
          if(!empty($newsComment["id_news"])){
              $record_model = 'News';
              $id_com = $newsComment["id_news"];
              foreach($eventsList as $event) {
                if($event['id_news'] == $newsComment["id_news"]){
                    $record_model = 'Event';
                    $id_com = $event['id_event'];
                }
              }

              $record_slug = "";
              foreach($newsList as $news){
                  if($news['id_news'] == $newsComment["id_news"]){
                      $record_slug = DB::slugify(utf8_encode($news['title']));
                  }
              }

            fputs($fp, "  comment_" . $newsComment["id_news_comments"] . ":\n");
            fputs($fp, "    id: " . $newsComment["id_news_comments"] . "\n");
            fputs($fp, "    record_model: " . $record_model . "\n");
            fputs($fp, "    record_id: " . $id_com . "\n");
            fputs($fp, "    record_slug: " . $record_slug . "\n");
            fputs($fp, "    author_name: NULL\n");
            fputs($fp, "    author_email: NULL\n");
            fputs($fp, "    author_website: NULL\n");
            fputs($fp, "    body: " . str_replace(array(":", "\n", "jscripts"), array("&#58;", "", "js"), (DB::htmlaccents($newsComment["text"], true, false))) . "\n");
            fputs($fp, "    is_delete: 0\n");
            fputs($fp, "    edition_reason: NULL\n");
            fputs($fp, "    reply: NULL\n");
            fputs($fp, "    user_id: " . $newsComment["creation_user"] . "\n");
            fputs($fp, "    created_at: '" . $newsComment["datetime_creation"] . "'\n");
            fputs($fp, "    updated_at: '" . $newsComment["datetime_modification"] . "'\n");
          }
      }
  }





  
 fclose($fp);
 if( $fp = fopen("../../data/fixtures/forum.yml","w") ) {
     echo 'Lecture/Ecriture du fichier fixtures forum ...<br/>';
 }

  /**********************************************/
  /*                ForumsCategory              */
  /**********************************************/

  $query = "SELECT SQL_CALC_FOUND_ROWS `forum_category`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`forum_category` forum_category ";

 echo 'Parsing forum_category..<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing forum_category...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $forumCategoryList[] = array(

                    "id_category" => $row->id_category,
                    "name_category" => $row->name_category,
                    "order_category" => $row->order_category,
                    "creation_user" => $row->creation_user,
                    "datetime_creation" => $row->datetime_creation,
                    "modification_user" => $row->modification_user,
                    "datetime_modification" => $row->datetime_creation);
           }
      }

      fputs($fp, "sfSimpleForumCategory:\n");
      foreach($forumCategoryList as $forumCat) {
            fputs($fp, "  sfSimpleForumCategory_" . $forumCat["id_category"] . ":\n");
            fputs($fp, "    id: " . $forumCat["id_category"] . "\n");
            fputs($fp, "    name: " . utf8_encode($forumCat["name_category"]) . "\n");
            fputs($fp, "    rank: " . $forumCat["order_category"] . "\n");
            fputs($fp, "    slug: " . DB::slugify(utf8_encode($forumCat["name_category"])) . "\n");
            fputs($fp, "    created_at: '" . $forumCat["datetime_creation"] . "'\n");
            fputs($fp, "    updated_at: '" . $forumCat["datetime_modification"] . "'\n");
      }
  }

  /**********************************************/
  /*                   Forums                   */
  /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `forum`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`forum` forum ";

 echo 'Parsing forum..<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing forum...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $forumList[] = array(

                    "id_forum" => $row->id_forum,
                    "id_category" => $row->id_category,
                    "name" => $row->name,
                    "description" => $row->description,
                    "order" => $row->order,
                    "id_last_post" => $row->id_last_post,
                    "nb_topic" => $row->nb_topic,
                    "nb_post" => $row->nb_post,
                    "visibility" => $row->visibility,
                    "type" => $row->type,
                    "creation_user" => $row->creation_user,
                    "datetime_creation" => $row->datetime_creation,
                    "modification_user" => $row->modification_user,
                    "datetime_modification" => $row->datetime_creation);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "sfSimpleForumForum:\n");
      foreach($forumList as $forum) {
            fputs($fp, "  sfSimpleForumForum_" . $forum["id_forum"] . ":\n");
            fputs($fp, "    id: " . $forum["id_forum"] . "\n");
            fputs($fp, "    name: " . utf8_encode($forum["name"]) . "\n");
            fputs($fp, "    description: " . utf8_encode($forum["description"]) . "\n");
            fputs($fp, "    rank: " . $forum["order"] . "\n");
            fputs($fp, "    category_id: " . $forum["id_category"] . "\n");
//            fputs($fp, "    latest_post_id: " . $forum["id_last_post"] . "\n");
            fputs($fp, "    nb_posts: " . $forum["nb_post"] . "\n");
            fputs($fp, "    nb_topics: " . $forum["nb_topic"] . "\n");
            fputs($fp, "    created_at: '" . $forum["datetime_creation"] . "'\n");
            fputs($fp, "    updated_at: '" . $forum["datetime_modification"] . "'\n");
      }
  }

  /**********************************************/
  /*                 Forum Topics               */
  /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `forum_topic`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`forum_topic` forum_topic ";

 echo 'Parsing forum_topic..<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing forum_topic...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $forumTopicList[] = array(

                    "id_topic" => $row->id_topic,
                    "id_forum" => $row->id_forum,
                    "title" => $row->title,
                    "nb_view" => $row->nb_view,
                    "type" => $row->type,
                    "id_last_post" => $row->id_last_post,
                    "id_first_post" => $row->id_first_post,
                    "nb_post" => $row->nb_post,
                    "locked" => $row->locked,
                    "creation_user" => $row->creation_user,
                    "datetime_creation" => $row->datetime_creation,
                    "modification_user" => $row->modification_user,
                    "datetime_modification" => $row->datetime_creation);
           }
      }

      fputs($fp, "\n");
      fputs($fp, "sfSimpleForumTopic:\n");
      foreach($forumTopicList as $forumTopic) {
            fputs($fp, "  sfSimpleForumTopic_" . $forumTopic["id_topic"] . ":\n");
            fputs($fp, "    id: " . $forumTopic["id_topic"] . "\n");
            fputs($fp, "    title: " . str_replace(array(":"), array("->"), utf8_encode($forumTopic["title"])) . "\n");
            fputs($fp, "    is_sticked: 0\n");
            fputs($fp, "    is_locked: " . $forumTopic["locked"] . "\n");
            fputs($fp, "    forum_id: " . $forumTopic["id_forum"] . "\n");
//            fputs($fp, "    latest_post_id: " . $forumTopic["id_last_post"] . "\n");
            fputs($fp, "    user_id: " . $forumTopic["creation_user"] . "\n");
            fputs($fp, "    nb_posts: " . $forumTopic["nb_post"] . "\n");
            fputs($fp, "    nb_views: " . $forumTopic["nb_view"] . "\n");
            fputs($fp, "    created_at: '" . $forumTopic["datetime_creation"] . "'\n");
            fputs($fp, "    updated_at: '" . $forumTopic["datetime_modification"] . "'\n");
      }
  }

 fclose($fp);
 if( $fp = fopen("../../data/fixtures/forumPost.yml","w") ) {
     echo 'Lecture/Ecriture du fichier fixtures forum ...<br/>';
 }

  /**********************************************/
  /*                 Forum Posts                */
  /**********************************************/

 $query = "SELECT SQL_CALC_FOUND_ROWS `forum_post`.* "
        . "FROM `". MYSQL_DBNAME_WEBSITE. "`.`forum_post` forum_post ";

 echo 'Parsing forum_post..<br/>';
 if( ( $result = $myDb->query( $query ) ) !== FALSE ) {
     echo 'Parsing forum_post...OK<br/>';

     if( $result->num_rows > 0 ) {
        while( $row = $result->fetch_object() ){
                $forumPostList[] = array(

                    "id_post" => $row->id_post,
                    "id_topic" => $row->id_topic,
                    "id_forum" => $row->id_forum,
                    "text" => $row->text,
                    "type" => $row->type,
                    "creation_user" => $row->creation_user,
                    "datetime_creation" => $row->datetime_creation,
                    "modification_user" => $row->modification_user,
                    "datetime_modification" => $row->datetime_creation);
           }
      }

      fputs($fp, "sfSimpleForumPost:\n");
      foreach($forumPostList as $forumPost) {
            $findTopicId = false;
            $findForumId = false;

            foreach($forumTopicList as $forumTopic){
                if($forumTopic['id_topic'] == $forumPost["id_topic"]){
                    $findTopicId = true;
                    $titleTopic = $forumTopic['title'];
                }
            }

            foreach($forumList as $forum){
                if($forum['id_forum'] == $forumPost["id_forum"]){
                    $findForumId = true;
                }
            }

            foreach($userList as $user){
                if($user['id'] == $forumPost["creation_user"]){
                    $author_name = $user['username'];
                }
            }

            if($findForumId && $findTopicId){
                fputs($fp, "  sfSimpleForumPost_" . $forumPost["id_post"] . ":\n");
                fputs($fp, "    id: " . $forumPost["id_post"] . "\n");
                $content = str_replace(array(":", "\r\n", "[color=green]", "[/color]", /*"js",*/ "jscripts"), array("&#58;", "", "", "", /*"/js/jquery",*/ "js"), (DB::htmlaccents(nl2br(utf8_encode($forumPost["text"])), true, false)));
                $content = str_replace("\n", "", $content);
                fputs($fp, "    title: " . str_replace(array(":"), array("->"), utf8_encode($titleTopic)) . "\n");
                fputs($fp, "    content: " . $content . "\n");
                fputs($fp, "    topic_id: " . $forumPost["id_topic"] . "\n");
                fputs($fp, "    forum_id: " . $forumPost["id_forum"] . "\n");
                fputs($fp, "    user_id: " . $forumPost["creation_user"] . "\n");
                fputs($fp, "    author_name: Manu\n");
                fputs($fp, "    created_at: '" . $forumPost["datetime_creation"] . "'\n");
                fputs($fp, "    updated_at: '" . $forumPost["datetime_modification"] . "'\n");
            }
      }
  }
  

 /****************** End ******************/

  fclose($fp);
  echo '...END<br/>';

 
?>